<?php
/**
 * Created by JetBrains PhpStorm.
 * User: FangXuanLing
 * Date: 13-11-20
 * Time: 上午10:56
 * To change this template use File | Settings | File Templates.
 */
class Post extends CActiveRecord{
    public static function model($className=__CLASS__)
    {
        return parent::model($className);
    }
    //如果表名和模型名不一致，需要重写下该方法
    public function tableName()
    {
        return 'tbl_post';
    }

    //定义下主键
    public function primaryKey(){
        return "id";
    }

    //定义验证规则
    public function rules(){
        return array(
            array('title,content',"required"),
        );
    }

    //定义关联表关系
    //请参考：http://www.yiichina.com/guide/database.arr
    public function relations(){
        return array(
            'cate'=>array(self::BELONGS_TO,'Category','cid'),
            'comment'=>array(self::HAS_MANY,'Comment','post_id'),
        );
    }


}